package com.xxzuibang.day6;

//数组的拷贝
public class Demo04 {
    public static void main(String[] args) {
        /*int[] arr1={10,20,30};
        //创建一个新的数组arr2，开辟新的数据空间
        int[] arr2=new int[arr1.length];
        System.out.println(arr1);
        System.out.println(arr2);
        //遍历arr1把每一个元素拷贝到arr2对应的元素位置
        for (int i = 0; i < arr1.length; i++) {
            arr2[i]=arr1[i];
        }
        //改一下arr2的元素会不会对arr1造成影响
        arr2[0]=200;

        System.out.println("arr1的元素");
        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr1[i]);
        }
        System.out.println("arr2的元素");
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }*/

        //数组的拷贝思路
        //1.定义一个静态初始数组arr1
        int[] arr1={354,23,656,76,88,453};
        //2.定义一个动态数组arr2长度和arr1长度一样
        int[] arr2=new int[arr1.length];
        //3.遍历arr1数组，把arr1里面的每一个值赋给arr2
        for (int i = 0; i < arr1.length; i++) {
            arr2[i]=arr1[i];
        }
        //4.分别遍历arr1和arr2数组查看拷贝结果
        System.out.println("arr1数组信息如下：");
        System.out.print("[");
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(i==arr1.length-1?arr1[i]:arr1[i]+",");
        }
        System.out.println("]");
        System.out.println("arr2数组信息如下：");
        System.out.print("[");
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(i==arr2.length-1?arr2[i]:arr2[i]+",");
        }
        System.out.println("]");





    }
}
